<?php

namespace App\Http\Controllers;


use Illuminate\Http\Request;

class TestController extends Controller
{


    public function test_db()
    {
        $result = \DB::select("select * from users");
        dump($result);
    }




    public function helloWorld()
    {
        return view('helloPage');
    }

    public function to_reg()
    {
        return view('reg');
    }

    public function do_reg(Request $request)
    {
        //接收客户端提交的所有参数
        $tmp = $request->input();
        dump($tmp);

        //接收客户端提交的指定参数
        $age = $request->input('age');
        dump($age);

        //第二个参数指定默认值,当客户端没有提交sex参数时,将使用该默认值作为sex的值
        $sex = $request->input('sex', '男');
        dump($sex);


        /*
         * 使用\DB:insert('原生SQL')或\DB:select('原生SQL')
         * 或\DB::update('原生SQL')或\DB::delete('原生SQL')
         * 做数据库操作
         */
        //获取参数
        $user_name = $request->input('user_name');
        $age = $request->input('age');

        $this->原生insert($user_name, $age);
        $this->原生select($user_name, $age);

    }


    private function 原生insert($user_name, $age)
    {
        $insert = \DB::select("insert into users(user_name, age) values($user_name,$age)");//插入一条数据
        dump($insert);
    }

    private function 原生select($user_name, $age)
    {
        $select = \DB::select('select * from users');//查询数据
        dump($select);
    }

    private function 原生update($user_name, $age)
    {
        //  \DB::update("SQL语句");
    }

    private function 原生delete($user_name, $age)
    {
        //  \DB::delete("SQL语句");
    }
}